import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';
import 'package:path/path.dart' as path;

class HttpAssistantService {
  static Future<Response> chatRoomNotification(int page, int size) async {
    return await BaseConfig.httpBase
        .get('/api/chat_rooms/assistant/notification', {
      'page': page,
      'size': size,
    });
  }

  static Future<Response> chatRoomAssistant() async {
    return await BaseConfig.httpBase.get('/api/chat_rooms/assistant', {});
  }

  static Future<Response> currentMessages(
      {String messageId, String entryPoint}) async {
    return await BaseConfig.httpBase.get('/api/chat_rooms/assistant/messages', {
      'message_id': messageId,
      'entry_point': entryPoint,
    });
  }

  static Future<Response> historyMessages(
      {String messageId, String entryPoint}) async {
    return await BaseConfig.httpBase
        .get('/api/chat_rooms/assistant/history_messages', {
      'message_id': messageId,
      'entry_point': entryPoint,
    });
  }

  static Future<Response> sendMessage({String message,int questionId}) async {
    return await BaseConfig.httpBase
        .postJson('/api/chat_rooms/assistant/messages', {
      'message': message,
      'question_id':questionId,
    });
  }

  /// 授权
  static Future<Response> broadcastingAuth(
      {String socketId, String channelName}) async {
    return await BaseConfig.httpBase.postJson('/broadcasting/auth', {
      'socket_id': socketId,
      'channel_name': channelName,
    });
  }

  /// 发送图片
  static Future<Response> sendImage(String filePath,
      {ProgressCallback onSendProgress}) async {
    final file =
        await BaseConfig.httpBase.formFile(filePath, path.basename(filePath));

    return BaseConfig.httpBase.postForm(
        '/api/chat_rooms/assistant/image',
        {
          'file': file,
        },
        onSendProgress: onSendProgress);
  }

  /// 授权
  static Future<Response> suggest({String queryText}) async {
    return await BaseConfig.httpBase.get('/api/chat_rooms/assistant/suggest', {
      'queryText': queryText,
    });
  }

  /// 授权
  static Future<Response> assistantUnRead() async {
    return await BaseConfig.httpBase
        .get('/api/chat_rooms/assistant/unread', {});
  }
}
